

import sys, os

#import ui
import main
import core.base
from core.base import Plugin
from core import util
from core.manager import PluginManager

import settings

import pycallgraph

class API(object):
    _instance = None
    __slots__ = ("app", "plugin_manager")
    
    def __new__(cls):
        if cls._instance is None:
            cls._instance = object.__new__(cls)
            cls._instance.app = None
        return cls._instance
    
    def initialize(self):
        
        
        self.app = main.App()
        
        self.plugin_manager = PluginManager()
        self.plugin_manager.init(settings.BASEDIR + '/res/plugins.yaml', 
                                 settings.BASEDIR + '/plugins',
                                 self.app.scene)
        
        self.app.setup_listeners()
        import core.std
        self.plugin_manager.load()
        self.app.set_db(settings.BASEDIR + "/res/standard_db.fs", override=True)
        
        self.app.main_window.update_views()
        
    def run(self):
        self.app.run_ui()
        
    def __getattr__(self, name):
        return self.app.scene.get_type(name)
    
        